package com.example.contentprovidermodule

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView

class PersonAdapter(context: Context,
					resource:Int, private val personList:ArrayList<Person>):ArrayAdapter<Person>(context,resource,personList) {

	inner class ViewHolder(val name: TextView, val number: TextView, val email: TextView, val address: TextView)
	override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {



		val view:View
		val viewHolder:ViewHolder
		if(convertView==null){
			view = LayoutInflater.from(context).inflate(R.layout.listview_item,parent,false)
			val name = view.findViewById<TextView>(R.id.name_lv)
			val number = view.findViewById<TextView>(R.id.number_lv)
			val email = view.findViewById<TextView>(R.id.name_email)
			val address = view.findViewById<TextView>(R.id.number_address)
			viewHolder = ViewHolder(name, number, email, address)
			view.tag=viewHolder
		}else{
			view=convertView
			viewHolder=view.tag as ViewHolder
		}

		val tempListItem = this.personList.get(position)
		viewHolder.name.setText(tempListItem.name)
		viewHolder.number.setText(tempListItem.number)
		viewHolder.email.setText(tempListItem.email)
		viewHolder.address.setText(tempListItem.address)
		return view
	}

	override fun getCount(): Int {
		return this.personList.size
	}


}